package com.example.springboot_demo.config;

import com.example.springboot_demo.controller.FormController;
import com.example.springboot_demo.interceptor.MyInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: ideaAdmin

 * Date: 2022/2/15:12:12
 * Description:
 */

@Configuration
public class InterceptorConfiguration implements WebMvcConfigurer {


    /**
     * 根据类型注入
     * required = false :表示如果找不到需要的对象 则不进行注入
    */
    @Autowired(required = false)
    private HandlerInterceptor myInterceptor;

    /**
     * 根据名称注入：myInterceptor1
     */
    @Resource
    private HandlerInterceptor myInterceptor1;

    @Autowired
    private FormController formController;


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        ////建造者设计模式 可以一直点方法 然后构建出一个庞大的对象
        registry.addInterceptor(myInterceptor)
                .addPathPatterns("/form/**")
                .excludePathPatterns("").order(0);
    }
}
